package com.shuo.dsa.sort;

import java.util.Arrays;

/**
 * Created by shuoGG on 2018/9/10
 */
public class ShuoGGBubble {
    public static void main(String[] args) {
        int[] arrays = {2, 5, 1, 3, 4};
        for (int i = 0; i < arrays.length - 1; i++) {
            boolean isChange = false;
            for (int j = 0; j < arrays.length - i - 1; j++) {
                if (arrays[j] > arrays[j + 1]) {
                    swap(arrays, j, j + 1);
                    isChange = true;
                }
            }
            if (!isChange) break;
        }
        System.out.println(Arrays.toString(arrays));
    }

    private static void swap(int[] target, int index1, int index2) {
        int temp = target[index1];
        target[index1] = target[index2];
        target[index2] = temp;
    }
}
